<template>
	<view class="index">
		<!-- 顶部自定义导航栏 -->
		<view class="tapbar">
			<view class="tapbar-left" @click='loginToFlag'>
				<text class="iconfont icon-xiangzuojiantou" @click="loginToFlag"></text>
			</view>
			<view class="tapbar-center">
				<text>momo笔记</text>
			</view>
			<view class="tapbar-right">

			</view>
		</view>
		<view class='login-M' v-show="flag">
			
			<img src="../../static/M.png" alt="" v-show="flag" />
			<text v-show="flag">momo笔记</text>
		</view>
		<view class='login-btn' v-show='flag'>
			<button @click="RBAC_Login">微信授权一键登录</button>
			<button @click="phoneLogin">手机号登录/注册</button>
		</view>
		<view class="lg-user" v-show='!flag'>
			<p><text>你好,</text></p>
			<p><text>欢迎来到momo笔记!</text></p>
		</view>
		<view class='lg-user-pass' v-show='!flag'>
			<p class='lg1'>
				<text>+86<text class='iconfont icon-xiajiantou'></text></text>
				<input type="text" v-model="phoneCode" placeholder="请输入您的电话" />
			</p>
			<p class='lg2'>
				<input type="text" v-model='codes' placeholder="请输入验证码" />
				<text class='text1'>{{code}}</text>
				<text @click='getCode' class='text2'>获取验证码</text>
			</p>
			<p class='lg3' @click="loginToHome">

				<text>登</text>
				<text>录</text>
			</p>
		</view>
		<view class='login-agreement'>

			<p class='text-agreement'>登录代表同意
				<text style='color:#5997f8'>《用户协议》</text>和
				<text style='color:#5997f8'>《隐私协议》</text>
			</p>
		</view>

		<u-loading :show="true"></u-loading>
		<view class='tanPopUpShow' v-show='tanshou'>
			<view class='tan-content' :class="fs?'a':''">
				<p class='tan-index1'>
					<img src="../../static/M.png" alt="" style='width: 30px;height: 30px;' />
					<text>momo笔记</text>
					<text>申请</text>
				</p>
				<p class='tan-index2'>
					<text>使用你的手机号码</text>
				</p>
				<p class='tan-index3'>
					<text>{{15231653859}}</text>
					<text>微信绑定手机号</text>
				</p>
				<p class='tan-index4'>
					<text>使用其他手机号</text>
				</p>
				<p class='tan-index5'>
					<button @click="noflag">拒绝</button>
					<button @click="yesflag">允许</button>
				</p>
			</view>
		</view>


	</view>
</template>
<script setup>
	import {
		ref,
		onMounted,
	} from "vue"
	const to = () => {

	}
	const tanshou = ref(false)
	const fs = ref(false)

	const RBAC_Login = () => {
		tanshou.value = true
		fs.value = true
	}

	// 允许按钮
	const yesflag = () => {
		tanshou.value = false
		fs.value = false
		uni.navigateTo({
			url: '/pages/home/index/index'
		});
	}


	// 拒绝按钮
	const noflag = () => {
		tanshou.value = false
		fs.value = false
	}

	// 验证码
	const codes = ref("")
	const code = ref("")
	// 获取验证码
	const getCode = () => {
		code.value = generateRandomCode(6)
	}
	const flag = ref(true)

	//在起始页面跳转到test.vue页面并传递参数
	const phoneLogin = () => {
		flag.value = false

	}
	const loginToFlag = () => {
		if (flag.value == false) {
			flag.value = true
		}
	}
	const show = ref(false)

	// 手机号的正则表达式
	const phoneReg = /^1[3-9]\d{9}$/
	const phoneCode = ref('')
	const loginToHome = () => {
		if (phoneReg.test(phoneCode.value)) {
			if (code.value == codes.value) {
				console.log(generateRandomCode(6))

				uni.showToast({
					title: '登陆成功',
					//将值设置为 success 或者直接不用写icon这个参数
					icon: 'success',
					//显示持续时间为 2秒
					duration: 1000
				})
				setInterval(() => {
					uni.navigateTo({
						url: '/pages/home/index/index'
					});
					flag.value = false
				}, 1000)

			} else {

			}

		} else {

		}
	}

	function generateRandomCode(length) {
		let code = '';
		const characters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
		const charactersLength = characters.length;
		for (let i = 0; i < length; i++) {
			code += characters.charAt(Math.floor(Math.random() * charactersLength));
		}
		return code;
	}

	// 示例用法
	console.log(generateRandomCode(6), '生成随机6位随机数'); // 生成一个包含6个字符的随机验证码
</script>
<style scoped lang="scss">
	.tapbar {
		padding: 0px 12px;
		height: 100px;
		display: flex;
		align-items: center;
		padding-top: 45px;
		box-sizing: border-box;

		.tapbar-left {
			color: #000;
			flex: 1;
			font-size: 20px;
			font-weight: 600;
		}

		.tapbar-center {
			flex: 1;
			font-size: 20px;
			font-weight: 600;
			text-align: center;
		}

		.tapbar-right {
			flex: 1;
		}
	}

	.login-M {
		width: 100%;
		text-align: center;
		color: #8f8f8f;
		display: flex;
		flex-direction: column;
		justify-content: center;
		align-items: center;

		image {
			margin-top: 40px;
			margin-bottom: 20px;
			width: 200px;
			height: 200px;
		}

		text {
			font-size: 18px;
		}
	}

	.login-btn {
		padding: 0px 12px;

		button:nth-child(1) {
			margin-top: 70px;
			height: 60px;
			background-color: #5997f8;
			color: #fff;
			border-radius: 50px;
			line-height: 60px;
			font-size: 20px;
			font-weight: 500;
		}

		button:nth-child(2) {
			margin-top: 30px;
			height: 60px;
			color: #5997f8;
			border: 1.5px solid #5997f8;
			background-color: #fff;
			border-radius: 50px;
			line-height: 60px;
			font-size: 20px;
			font-weight: 500;
		}
	}

	.login-agreement {
		padding: 0px 12px;
		text-align: center;
		font-size: 18px;
		position: fixed;
		bottom: 60px;
		left: 0;
		right: 0;
	}

	.lg-user {
		padding: 0px 30px;

		margin-top: 80px;

		view {
			margin: 10px 0px;

			text {

				font-size: 25px;
				color: #5997f8;
				font-weight: 500;
			}
		}

	}

	.lg-user-pass {
		padding: 0px 30px;
		margin-top: 70px;

		.lg1 {
			display: flex;
			height: 40px;
			align-items: center;
			margin-top: 20px;

			text {
				font-size: 20px;
				color: #8f8f8f;
				margin-right: 20px;
			}
		}

		.lg2 {
			display: flex;
			height: 40px;
			align-items: center;
			margin-top: 20px;
			margin-bottom: 60px;

			.text1 {
				background-color: #fff;
				color: #5997f8;
				margin-right: 20px;
				font-size: 18px;

			}

			.text2 {
				background-color: #fff;
				color: #5997f8;
				font-size: 18px;
				font-weight: 600;

			}
		}

		.lg3 {
			height: 50px;
			line-height: 50px;
			font-size: 20px;
			text-align: center;
			color: #fff;
			background-color: #5997f8;
			border-radius: 50px;

			text:nth-child(1) {
				margin-right: 10px;
			}

			text:nth-child(2) {
				margin-left: 10px;
			}
		}

		view:nth-child(1) {
			border-bottom: 1px solid #f2f2f2;
		}

		view:nth-child(2) {
			border-bottom: 1px solid #f2f2f2;
		}
	}

	.tanPopUpShow {
		width: 100%;
		height: 100%;
		background-color: rgba(0, 0, 0, 0.4);
		position: fixed;
		bottom: 0;
		left: 0;
		right: 0;
		z-index: 1;

		.tan-content {
			height: 400px;
			background-color: #fff;
			position: fixed;
			left: 0;
			right: 0;
			bottom: 0;
			border-top-left-radius: 10px;
			border-top-right-radius: 10px;
			padding: 10px 20px 0px 20px;
			box-sizing: border-box;

			.tan-index1 {
				display: flex;
				height: 50px;
				align-items: center;

				text {
					margin: 0px 5px;
				}
			}

			.tan-index2 {
				height: 50px;
				line-height: 50px;
				font-size: 20px;
				font-weight: 500;
			}

			.tan-index3 {
				height: 50px;
				line-height: 50px;

				text:nth-child(1) {
					margin-left: 0px;
				}

				text:nth-child(2) {
					color: #8f8f8f;
				}

				text {
					margin: 0px 5px;
				}
			}

			.tan-index4 {
				height: 50px;
				line-height: 50px;

				text {
					color: #b9becb;
				}
			}

			.tan-index5 {
				height: 70px;
				margin-top: 50px;
				display: flex;

				button {
					width: 150px;
					height: 50px;
				}

				button:nth-child(1) {
					color: #58bf6b;
					background-color: #f2f2f2;
				}

				button:nth-child(2) {
					background-color: #58bf6b;
					color: #f2f2f2;
				}
			}
		}

		.a {
			animation: ping 1000ms;
			animation-timing-function: ease-in-out;
			animation-iteration-count: 1;
		}

		@keyframes ping {
			from {
				transform: translateY(100%);
			}

			to {
				transform: translateY(0%);
			}
		}


	}
</style>